package logic

import (
	"context"
	"zy31/rpc/user"

	"zy31/api/internal/svc"
	"zy31/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.GoodsListRequest) (resp *types.Response, err error) {
	list, err := l.svcCtx.UserRpc.GoodsList(l.ctx, &user.GoodsListRequest{Status: int64(req.Status)})
	if err != nil {
		return &types.Response{
			Msg:  "商品列表展示失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "商品列表展示成功",
		Data: list,
		Code: 200,
	}, nil
}
